package com.swt.testdemo.controller;


import com.swt.testdemo.config.ResponseMessage;
import com.swt.testdemo.form.SysLoginForm;
import com.swt.testdemo.service.SysLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author BleethNie
 * @version 1.0
 * @date 2020-01-08 15:15
 **/
@RestController
@RequestMapping("/sys")
@Api(tags = "系统管理--登录登出（完成）")
@Slf4j
public class SysLoginController {


    @Autowired
    private SysLoginService sysLoginService;

    @ApiOperation("01 用户登陆")
    @PostMapping(value = "/login")
  //  @SysLog(msg = "用户登陆",field = "#form.username")
    public ResponseEntity<ResponseMessage> login(@RequestBody SysLoginForm form) {
        ResponseMessage response = sysLoginService.login(form);
        return ResponseEntity.status(response.getStatus()).body(response);
    }

    @ApiOperation("02 用户登出")
    @PostMapping(value = "/logout")
    public ResponseEntity<ResponseMessage> logout() {
        ResponseMessage response = sysLoginService.logout();
        return ResponseEntity.status(response.getStatus()).body(response);
    }


    @ApiOperation("03 获取验证码")
    @GetMapping(value = "/captcha", produces = "image/png")
    @ApiImplicitParam(name = "uuid", value = "随机码", required = true, paramType = "query", dataType = "string", defaultValue = "8e04634d-3420-47f8-a1af-392d77301bb9")
    public byte[] captcha(String uuid) {
        return sysLoginService.captcha(uuid);
    }


    @ApiOperation("04 登陆破解码")
    @GetMapping(value = "/crack")
    @ApiImplicitParam(name = "uuid", value = "随机码", required = true, paramType = "query", dataType = "string", defaultValue = "8e04634d-3420-47f8-a1af-392d77301bb9")
    public ResponseEntity<ResponseMessage> crackUUid(String uuid) {
        ResponseMessage response = sysLoginService.crackUUid(uuid);
        return ResponseEntity.status(response.getStatus()).body(response);
    }


}
